﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCE.UI.Blocks;

namespace Baosight.ZNH.ZMCE.UI
{
    public partial class ZMCE92 : EFViewCmes
    {
        public ZMCE92()
        {
            InitializeComponent();
        }

        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(new EquipmentClassBlock().getIsLeaf("cmes.ce.isLeaf"));
            base.Initialize(initData);
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;

            if (!this.ValidateField())
            {
                this.ValidateMessagePopup();//弹出提示信息
                this.TempButtonOpen(true);//确定按钮生效
            }
            else
            {
                base.Submit(this.BuildSubmitEIInfo(eServiceName, "update", "result"), DoCommitCompleted);
            }
        }

        /// <summary>
        /// 修改后的回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void DoCommitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            EIInfo inInfo = e.EIInfo;
            if (inInfo.Status == -1)
            {                
                this.OnCommitMessagePopup(inInfo);//操作失败，消息提醒                
            }
            else
            {
                UpdateHomePageData(inInfo);
            }
            this.TempButtonOpen(true);
        }

        ///// <summary>
        ///// 重写基类方法：根据数据的改变更新主页面的数据
        ///// </summary>
        ///// <param name="data"></param>
        public override void UpdateHomePageData(EIInfo data)
        {
            // 数据发布
            IEventAggregator eventAggreator = Container.Resolve<IEventAggregator>();
            EIDataPublishedEvent dataPublishedEvent = eventAggreator.GetEvent<EIDataPublishedEvent>();
            dataPublishedEvent.Publish(data);
        }
    }
}

